﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using db;

namespace DMSMT.ServiceMgr
{
    public partial class SearchBill : Form
    {
        public SearchBill()
        {
            InitializeComponent();
        }

        private void SearchBill_Load(object sender, EventArgs e)
        {

        }

        private void btSearch_Click(object sender, EventArgs e)
        {
            string code = tbBillCode.Text.Trim();
            if (string.IsNullOrEmpty(code))
            {
                MessageBox.Show("请输入完整单号!");
                return;
            }
            string type="";
            foreach (Control c in gbTypes.Controls)
            {
                RadioButton rb = (RadioButton)c;
                if (rb.Checked)
                {
                    type = rb.Text;
                    break;
                }
            }
            SearchBillByType(type, code);
        }

        private void SearchBillByType(string type, string code)
        {
            if (type.Equals(rbBX.Text))
            {
                SearchBX(code);
            }
        }

        private void SearchBX(string code)
        {
            Log.LogText("开始查询包修单信息");
            String format = "select '{0}' 数据来源,re.jddh 单号,re.vin VIN,re.gs 工时,re.gsfy 工时费用,re.dqzd 单据状态 from {1} re where jddh like '%{2}%'";
            try
            {
                string sql = string.Format(format, "DMS", "ti_se_repair_list", code);
                sql += "union all\n" + string.Format(format, "一体化", "t_lqshdjdd@PV28", code);
                dgDMSPV.DataSource = Dao.searchDS("zj", sql).Tables[0];
            }
            catch (Exception ex)
            {
                Log.LogError(ex.Message);
            }
        }

        private void dgDMS_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
